package com.example.springboot.controller;

import com.example.springboot.entity.Device;
import com.example.springboot.entity.Instore;
import com.example.springboot.mapper.InstoreMapper;
import com.example.springboot.mapper.UserMapper;
import com.example.springboot.service.InstoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/instores")
public class InstoreController {
    @Autowired
    private InstoreMapper instoreMapper;

    @Autowired
    private InstoreService instoreService;

    @Autowired
    private UserMapper userMapper;

    //用get请求查询数据库信息
    @GetMapping
    public List<Instore> findAll(){
        return instoreMapper.findAll();//查询所有数据
    }

    //用post请求对数据库数据进行增加和修改
    @PostMapping
    public Integer save(@RequestBody Instore instore){
        Integer purchaserId = userMapper.selectId(instore.getBuyerName());
        instore.setPurchaserId(purchaserId);
        return instoreService.save(instore);//往数据库插入或更新数据
    }
}
